const { init } = require('./../../wxCloudClientSDK.umd.js')
// 指定云开发环境 ID
wx.cloud.init({
  env: "cloud1-9gel6ndh8e555155", // 当前的云开发环境 ID
});
    
const client = init(wx.cloud);

Page({
  data: {
    goodsInfo: {
      id: '',
      goodsName: '',
      description: '',
      price: 0,
      stock: 0,
      imageUrl: '',
      thumbnailUrl: '',
      sales: 0
    },
    
  },

  onLoad: function(options) {
    // options 包含传递过来的参数
    console.log("id: " + options.param1);

    this.queryGoodsDetail(options.param1);
  },

  queryGoodsDetail(id) {
    client.models.goods_info.get({
      filter: {
        where: {
         $and: [{
           _id: {
             $eq: id
           },
         },
       ],
        }
      }
    }).then(res => {
     console.log("goods_info: " + res.data);
     this.parseGoodsData(res.data);
   }).catch(res => {
     console.log("goods_info err: " + res)
   });
  },

  parseGoodsData(data) {
    const goods = {
      id: data._id,
      goodsName: data.goodsName,
      description: data.description,
      price: data.price,
      stock: data.stock,
      imageUrl: data.imageUrl,
      thumbnailUrl: data.thumbnailUrl,
      sales: 0
    };

    this.setData({
      goodsInfo: goods
    });
  },

  

});